package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.GroupView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface GroupViewMapper extends JpaRepository<GroupView, Long>, JpaSpecificationExecutor<GroupView> {

    @Query(value = "select p from GroupView p where p.applicationId = :appId and p.groupCode = :groupCode")
    GroupView findByGroupCode(long appId, String groupCode);

    @Query(value = "select p from GroupView p where p.applicationId = :appId and p.groupName = :groupName")
    Collection<GroupView> findListByGroupName(long appId, String groupName);

    Page<GroupView> findAll(Specification<GroupView> specification, Pageable pageable);
}
